<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/view/common/taglibs.jsp"%>
<html>
	<head>
		<title>角色授权</title>
		<script src="${contextPath}/scripts/jquery/jquery-1.8.3.min.js" type="text/javascript"></script>
		<script src="${contextPath}/scripts/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
		<link href="${contextPath}/styles/default.css" rel="stylesheet" type="text/css" />
		<script type="text/javascript">
		
		function choose(){
			var check = $("input[name='mid']:checked"); //得到所有被选中的checkbox
			   var codes='',names='',tmpid='',tmpname='';              //定义变量
			   check.each(function(i){         //循环拼装被选中项的值
				   tmpid=$(this).attr('id');
				   tmpname=$(this).val();
				   if(tmpid!=''&&tmpname!=''){
					   if(i!=check.length-1){
						   codes+=tmpid+',';
						   names+=tmpname+',';   
					   }else{
						   codes+=tmpid;
						   names+=tmpname;
					   }
				   }
			    });
			   
			window.opener.choose_oper(codes,names);
			window.close();
		}
		
		function dock(el){
			$(el).parent().parent().parent().find("input").attr('checked',$(el).is(':checked'));
		}
		
		$(document).ready(function(){            
			$("#check_all").click(function(){  
				$('[type=checkbox]').attr('checked', $("#check_all").is(':checked'));
			});
			$("span").click(function(e){
				if($(e.target).find("input:first").length>0){
					$(e.target).find("input:first").attr('checked',!$(e.target).find("input:first").is(':checked'));
				}
			});
			
			var d=$("#init_codes").val();
			if(d!=null&&d.length>0){
				var ary=d.split(",");
				if(ary!=null&&ary.length>0){
					for(var i=0;i<ary.length;i++){
						if(ary[i]!=''&&$("#"+ary[i]).length>0){
							$("#"+ary[i]).attr("checked",true);
						}
					}
				}
			}
		});
		</script>
	</head>
	<body>
	<br />
      <form name="searchForm" id="searchForm" method="post" action="chooseMulti.do">
      
	<div class="xt_main_right_center" style="width: 90%;margin-left: 10px" >
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
		  <tr>
		    <td height="25" align="left"><font color="#0066CC"><strong>权限列表：</strong></font></td>
		    <td height="25" align="center"><input id="check_all" type="checkbox"/>全选(整页)</td>
		    <td height="25" align="right"><input type="button" value="确定" style="width: 80px;height: 30px" onclick="choose()"/></td>
		  </tr>
		</table>
		
	<s:iterator value="opers" var="vx" status="st">
	<table width="100%" border="0" cellpadding="1" cellspacing="1">
	<tr><td>
		<span><input type="checkbox" name="mid" value="<s:property value='name' />(根菜单)" id="<s:property value='code' />"/>&nbsp;<font color="#0066CC"><s:property value="name" /></font></span>
		<input type="checkbox" onclick="dock(this)"/>全选(模块)
		<br/>
	</td></tr>
		<!-- <div>折叠 -->
		<s:if test="childs!=null">
			<s:iterator value="childs" var="vm">
			<tr><td>
				<span>&nbsp;&nbsp;&nbsp;&nbsp;</span>
				<span><input type="checkbox"  name="mid" value="<s:property value='name' />(子菜单)" id="<s:property value='code' />"/>&nbsp;<s:property value="name" /></span><br/>
			</td></tr>
			
				<s:if test="childs!=null">
				<tr><td>
					<s:iterator value="childs" var="vl" status="sti">
						<s:if test="%{!code.startsWith('M_')}">
							<s:if test="#sti.index==1"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></s:if>
							<s:else><span>&nbsp;&nbsp;&nbsp;&nbsp;</span></s:else>
							<span><input name="mid"  value="<s:property value='name' />(<s:property value='#vm.name' />)" id="<s:property value='code' />" type="checkbox" /><s:property value="name" /></span>
						</s:if>
					</s:iterator>
					<br/>
					</td></tr>
				</s:if>
			</s:iterator>
		</s:if>
		<!-- </div> -->
		</table>
	</s:iterator>
	</div>
	<div align="center"><input type="button" value="确定" style="width: 80px;height: 30px" onclick="choose()"/></div>
	<input type="hidden" id="init_codes" value="<s:property value="codes"/>" />
	</form>
	</body>
</html>